package com.example.demo.config;

import com.example.demo.service.WsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import java.io.IOException;
import java.time.LocalDateTime;

@Slf4j
@Configuration
public class MessageJob {

    @Autowired
    private WsService wsService;

    /**
     * 每5s发送
     */
    @Scheduled(cron = "*/10 * * * * *")
    public void run() {
        try {
            wsService.broadcastMsg("服务端消息 " + LocalDateTime.now());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
